﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace 历史记录.DataAccessLayer
{
    /// <summary>
    /// 数据库访问层
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IDAL<T> : IDisposable
          where T : Model, new()
    {
        /// <summary>
        /// 插入列表
        /// </summary>
        /// <param name="table">插入表名称</param>
        /// <param name="insertObjs">插入数据列表</param>
        /// <returns></returns>
        bool Insertable(string table, List<T> insertObjs);

        /// <summary>
        /// 获取表名称列表
        /// </summary>
        /// <returns></returns>
        List<string> GetTableList();

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <typeparam name="TResult">返回的值的类型</typeparam>
        /// <param name="table">表名</param>
        /// <param name="Select">一个应用于每个源元素的转换函数</param>
        /// <param name="Where">查询条件</param>
        /// <returns></returns>
        IEnumerable<TResult> Queryable<TResult>(string table, Expression<Func<T, TResult>> Select, Expression<Func<T, bool>> Where = null) where TResult : new();

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="Where">查询条件</param>
        /// <returns></returns>
        IEnumerable<T> Queryable(string table, Expression<Func<T, bool>> Where = null);

        /// <summary>
        /// 创建新的表
        /// </summary>
        /// <param name="table">表名</param>
        void InitTables(string table);

        /// <summary>
        /// 删除表
        /// </summary>
        /// <param name="table">表名</param>
        /// <returns></returns>
        bool DropTable(string table);

        /// <summary>
        /// 刪除记录
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="predicate">删除条件</param>
        /// <returns></returns>
        bool DeleteMany(string table, Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 最晚时间
        /// </summary>
        /// <param name="table">表名</param>
        /// <returns></returns>
        DateTime Max(string table);

        /// <summary>
        /// 最早时间
        /// </summary>
        /// <param name="table">表名</param>
        /// <returns></returns>
        DateTime Min(string table);
    }
}